package logic

import (
	"context"
	"course_srv/models/redis"
	"errors"

	"course_srv/course"
	"course_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDelLogic {
	return &CartDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartDelLogic) CartDel(in *course.CartDelRequest) (*course.CartDelResponse, error) {
	err := redis.DelCart(int(in.UserId), int(in.CourseId))
	if err != nil {
		return nil, errors.New("购物车删除失败")
	}
	return &course.CartDelResponse{}, nil
}
